import sched
import time
import threading

counter = 0


def increment_counter(name):
    global counter
    print('Event：', time.time(), name)
    counter += 1
    print('Now', counter)


now = time.time()
print('START:', now)

sche = sched.scheduler(time.time, time.sleep)
first = sche.enter(2, 1, increment_counter, ('first',))
second = sche.enter(3, 1, increment_counter, ('second',))

# 开始一个线程执行事件
t = threading.Thread(target=sche.run)
t.start()

print(sche.empty())  # False
print(
    sche.queue)  # [Event(time=1629876146.1685424, priority=1, action=<function increment_counter at 0x000001FE4D92AD90>, argument=('first',), kwargs={}), Event(time=1629876147.1685424, priority=1, action=<function increment_counter at 0x000001FE4D92AD90>, argument=('second',), kwargs={})]

# 在主线程取消一个预定事件
sche.cancel(first)

t.join()
